/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React from 'react';
import AppNavigation from './app/navigator/appNavigation';
import {Provider} from 'mobx-react';
import store from './app/store/index';
import SplashScreen from 'react-native-splash-screen';
import SafeAreaViewPlus from './app/utils/safeAreaViewPlus';
import MyLoading from './app/components/MyLoading';

// import TestComponent from './app/test/TestComponent';

import Toast from 'react-native-easy-toast';

//将App组件中的this赋给全局的self
let self;
//所有子页面均可直接调用global.toast("")来吐司提示消息
global.toast = null;
global.mLoadingComponentRef = null

class App extends React.Component {
  componentDidMount() {
    //模拟数据到
    this.timer = setTimeout(() => {
      SplashScreen.hide();
    }, 100);

    //封装全局方法
    self = this;
    global.toast = function (message) {
      self.refs.toast.show(message);
    };
    global.mLoadingComponentRef = function (visible) {
      if (visible) {
        self.refs.mLoadingComponentRef.showLoading();
      } else {
        self.refs.mLoadingComponentRef.dismissLoading();
      }
    };
  }

  componentWillUnmount() {
    this.timer && clearTimeout(this.timer);
  }

  render() {
    return (
      <SafeAreaViewPlus enablePlus={false}>
        <Provider {...store}>
          <Toast ref="toast" opacity={0.8} />
          <MyLoading ref="mLoadingComponentRef" />
          {/*<TestComponent></TestComponent>*/}
          <AppNavigation />
        </Provider>
      </SafeAreaViewPlus>
    );
  }
}
export default App;
